package com.lc.luzhengtang.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.lc.luzhengtang.BaseApplication;
import com.lc.luzhengtang.R;
import com.zcx.helper.bound.BoundViewHelper;
import com.zcx.helper.scale.ScaleScreenHelperFactory;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 文 件 名: NewsListAdapter
 * 创 建 人: zhangyu
 * 创建日期: 16/12/24 19:55
 * 邮   箱: yuanchong121@gmail.com
 * 修改时间：
 * 修改备注：
 */
public class MineListAdapter extends RecyclerView.Adapter<MineListAdapter.ViewHolder> implements View.OnClickListener {

    private MyOnItemClickListener itemClickListener;
    List<String> list;
    private Context context;
    public String[] img_text2 = {"", "", "", "",
            ""};

    public String[] img_text = {"待付款", "待发货", "待收货", "待评价",
            "退款/收货"};
    public int[] imgs = {R.mipmap.daifukuan, R.mipmap.daifahuo,
            R.mipmap.daishouhuo, R.mipmap.daipingjia,
            R.mipmap.tuihuo,};

    public MineListAdapter(Context context, List<String> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public void onClick(View v) {

    }

    public static class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        @BindView(R.id.notify_text)
        TextView notifyText;
        @BindView(R.id.img_shouhuo)
        ImageView imgShouhuo;
        @BindView(R.id.text_shouhuo)
        TextView textShouhuo;


        public ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);

        }

        @Override
        public void onClick(View v) {
        }
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
       /* View view = BoundViewHelper.boundView(this, MyApplication.scaleScreenHelper.loadView((ViewGroup) LayoutInflater.from(parent.getContext())
                .inflate(R.layout.list_02_item_view, null)));*/
        View view = BoundViewHelper.boundView(this, ScaleScreenHelperFactory.getInstance().loadView((ViewGroup) LayoutInflater.from(context)
                .inflate(R.layout.item_mine, null)));
        ViewHolder vh = new ViewHolder(view);
        view.setOnClickListener(this);

        return vh;
    }


    @Override
    public void onBindViewHolder(final ViewHolder holder, final int position) {
/*自定义item的点击事件不为null，设置监听事件*/
        if (itemClickListener != null) {
            Log.d("onBindViewHolder", "itemClickListener != null" + "，itemview = " + holder.itemView.getId());
            holder.itemView.setClickable(true);
            holder.itemView.setEnabled(true);
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                    Log.d("111", "onClick");
                    itemClickListener.OnItemClickListener(holder.itemView, holder.getLayoutPosition());
                }
            });
        }

//        GridLayoutManager gridLayoutManager = new GridLayoutManager(context, 4);
        if (list.get(position).equals("0")) {
            holder.notifyText.setVisibility(View.GONE);
        }else if (TextUtils.isEmpty(BaseApplication.basePreferences.readUid())){
            list.clear();
        }

        else {
            holder.notifyText.setText(list.get(position));
            holder.notifyText.setVisibility(View.VISIBLE);
        }
        holder.imgShouhuo.setBackgroundResource(imgs[position]);
        holder.textShouhuo.setText(img_text[position]);


    }

    /**
     * Returns the total number of items in the data set hold by the adapter.
     *
     * @return The total number of items in this adapter.
     */
    @Override
    public int getItemCount() {
        return list.size();
    }

    /**
     * 列表点击事件
     *
     * @param itemClickListener
     */
    public void setOnItemClickListener(MyOnItemClickListener itemClickListener) {
        this.itemClickListener = itemClickListener;
    }

    public interface MyOnItemClickListener {

        void OnItemClickListener(View view, int position);
    }
}
